import { Injectable } from '@angular/core'
import { HttpClient } from '@angular/common/http';

import { Http, Response, Headers, RequestOptions, URLSearchParams } from '@angular/http'
import { TreeNode } from 'primeng/primeng'
import { Observable } from 'rxjs';
import { map } from "rxjs/operators";

@Injectable()
export class DictService {

    constructor(private http: HttpClient) { }

    /** 获取指定系统下的字典项 */
    listAll() {
        return this.http.get('/system/api/sysdict/list').pipe(
            map((res: Response) => res['data'])
        );
    }

    /** 根据ID获取配置项 */
    loadDictDetails(dcitId: number) {
        return this.http.get('/system/api/sysdict/loaddetail?id=' + dcitId).pipe(
            map((res: Response) => res['data'])
        );
    }

    /** 保存更新 */
    saveUpdate(dict: any) {
        return this.http.post('/system/api/sysdict/saveupdate', dict).pipe(
            map((res: Response) => res['data'])
        );
    }

    /** 删除指定字典项目 */
    deleteDict(dict: any) {
        return this.http.post('/system/api/sysdict/delete', dict).pipe(
            map((res: Response) => res['data'])
        );
    }
}